package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("setmealUserController")
@Slf4j
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    SetmealService setmealService;

    /**
     * 根据分类id查询套餐
     *
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache" ,key = "#categoryId")
    public Result<List<Setmeal>> getSetmealById(Long categoryId) {
        log.info("根据分类id查询套餐:{}", categoryId);
        List<Setmeal> list = setmealService.getSetmealById(categoryId);
        return Result.success(list);
    }

    /**
     * 根据套餐id查询包含的菜品
     *
     * @param id
     * @return
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> getDishByCategoryId(@PathVariable Long id) {
        log.info("根据套餐id查询包含的菜品:{}", id);
        List<DishItemVO> list = setmealService.getDishByCategoryId(id);
        return Result.success(list);
    }
}
